package com.llt.ai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.time.LocalDate;

/**
 * @Author: llt
 * @Date: 2025/7/31 22:46
 */
@RestController
public class OpenAiController {

    @Autowired
    private ChatClient chatClient;

    @CrossOrigin
    @GetMapping(value = "/ai", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> generateStreamAsString(@RequestParam(value = "message", defaultValue = "讲个笑话") String message) {
        return chatClient.prompt()
                .user(message)
                .system(p -> p.param("current_date", LocalDate.now()))
                .stream()
                .content();
    }
}
